home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Speech Synthesis Manager / Installer Source / ActionAtoms / AtomUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  1.9 KB  |  83 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2.  *
  3.  *    File:        AtomUtils.c -    C Source
  4.  *
  5.  *    Author:        Deric Horn
  6.  *
  7.  *    Common Action Atom utility functions
  8.  *
  9.  *    History:    <1>    (12/2/94) Created this file.
  10.  *
  11.  *----------------------------------------------------------------------------*/
  12.  
  13. #include    "AtomUtils.h"
  14.  
  15.  
  16. //    This routine strips the filename and the preceding ':' character from the
  17. //     pathname.
  18. //    Input - pointer to file pathname
  19. //    Output - modifies pointer
  20. OSErr    StripFileName(char *str)
  21. {
  22.     unsigned char len = str[0];
  23.     
  24.     while ((str[len] != ':') && (len > 0)) 
  25.         len--;
  26.     
  27.     if (len > 0) {
  28.         str[0] = len - 1;    // parse the ":" from the end of the pathname
  29.         return noErr;
  30.     }
  31.     return -1;
  32. }
  33.  
  34. long    DirIDFromSpecialPath( StringPtr path, short vRefNum )
  35. {
  36.     StringPtr    s = path;
  37.     OSType        folderType;
  38.     short        foundVrefNum;
  39.     long        foundDirID;
  40.     OSErr        err;
  41.     
  42.     for ( ; s[0] != '-' ; s++ )                //    step over 'spcl'
  43.         ;
  44.     
  45.     strncpy( (char*)&folderType, &(s[1]), 4 );
  46.     err = FindFolder( vRefNum, folderType, false, &foundVrefNum, &foundDirID );
  47.     
  48.     return( foundDirID );
  49. }
  50.  
  51. void    PathFromSpecialPath( StringPtr pathStorage, StringPtr path )
  52. {
  53.     StringPtr    s = path;
  54.     
  55.     for ( ; *s != ':' ; s++ )
  56.         ;
  57.     
  58.     pathStorage[0] = path[0] - (s-path) +1;                //    length of rest of string
  59.     BlockMove( s, &(pathStorage[1]) , pathStorage[0] );
  60. }
  61.  
  62.  
  63. OSErr    MakeFSSpecFromAAPB( FSSpecPtr myFS, StringPtr path, AAPBRecPtr myAAPBPtr )
  64. {
  65.     long    dirID;
  66.     Str63    pathStorage;
  67.     
  68.     if ( path[1] != ':' )            //    special directory in Sys Folder
  69.     {
  70.         dirID = DirIDFromSpecialPath( path, myAAPBPtr->targetVRefNum );
  71.         PathFromSpecialPath( pathStorage, path );
  72.         return ( FSMakeFSSpec( myAAPBPtr->targetVRefNum, dirID, pathStorage, myFS ) );
  73.     }
  74.     else
  75.     {
  76.         return ( FSMakeFSSpec( myAAPBPtr->targetVRefNum, 0L, path, myFS ) );
  77.     }
  78. }
  79.  
  80. void    pStrcpy(unsigned char *dest, unsigned char *src)
  81. {
  82.     BlockMove(src, dest, (long) *src + 1); 
  83. }